package com.niit.springbootshop.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.niit.springbootshop.tools.FileUtils;
import org.springframework.stereotype.Component;

/**
 * @author: hanliang
 * @create: 2021-05-13
 */
@Component
public class AlipayConfig {

    // 1. 设置参数（全局只需设置一次）
    static {
        Factory.setOptions(getOptions());
    }

    private static Config getOptions() {
        Config config = new Config();

        config.protocol = "https";

        // 沙箱环境修改为 openapi.alipaydev.com
        config.gatewayHost = "openapi.alipaydev.com";

        config.signType = "RSA2";

        config.appId = "2016080800192265";

        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = FileUtils.readFileOfTxt("/Users/hanliang/Documents/支付宝开放平台开发助手/CSR/xxx.com_私钥.txt");

        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
        config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SavmbGlhuTOaE1N95TwpiESUuuNS1FZUU/tlZZF+pX32oV3qoiHAKN4EIjqcKwdAViP6Ge0kk8wsy3WlvoajXTnCMnqzLtbAjM22hl1Cjj5wmouQWN9J330/Y+8fvZnXuQI1E13Ax2nscvsu62fePqrrUYlg1CIVMGCIF0ZdK2+2dRX2wn8a+arsHKG34z2LngyHfH3tgMcq2Dw5+K3pIVIuvbQLlmIuCv0Le5ttRf9Qkq6vgBRnPDj35FHza0YrTxaXgcp1yxrfMAUpSuJS0Q5ehnHeWU/C1RanxlwevVLC35fSy5B8VlQz1zM8vZW1GhrfmV8cOT30edXpzsnQIDAQAB";

        config.merchantCertPath="/Users/hanliang/Downloads/appCertPublicKey_2016080800192265.crt";
        config.alipayCertPath="/Users/hanliang/Downloads/alipayCertPublicKey_RSA2.crt";
        config.alipayRootCertPath="/Users/hanliang/Downloads/alipayRootCert.crt";
        //可设置异步通知接收服务地址（可选）
        config.notifyUrl = "";

        return config;
    }
}
